import 'package:dk_flutter_base/dk_ui.dart';

enum CustomMediaTyp { Camera, Gallery, All }

class OpenCustomMediaBean {
  ///打开媒体的类型
  ///* Camera 只打开相机
  ///* Gallery 只打开相册
  ///* All 相册和相机
  String mediaType;

  int maxSelectable;

  ///图片上传参数，是否上传：null不上传，非null上传
  UploadConfigBean uploadConfig;

  ///需要打的自定义水印
  List<String> waterContent;

  ///是否打位置水印
  bool addressWatermark;

  ///是否使用native的loadingDialog
  bool useNativeLoadingDialog;

  /// 基本功能
  ///
  /// 只选择拍照或者选择图片
  OpenCustomMediaBean.normal({
    @required CustomMediaTyp mediaType,
    this.maxSelectable = 1,
    this.useNativeLoadingDialog = true,
  }) {
    this.mediaType = convertType(mediaType);
  }

  /// 基本功能+打水印
  ///
  /// 拍照或者选择图片后加水印
  OpenCustomMediaBean.waterMark({
    @required CustomMediaTyp mediaType,
    this.maxSelectable = 1,
    this.useNativeLoadingDialog = true,
    this.addressWatermark = false,
    @required this.waterContent,
  }) {
    this.mediaType = convertType(mediaType);
  }

  /// 基本功能+上传（压缩后上传）
  ///
  /// 拍照或者选择图片后上传到七牛
  OpenCustomMediaBean.upload({
    @required CustomMediaTyp mediaType,
    this.maxSelectable = 1,
    this.useNativeLoadingDialog = true,
    @required this.uploadConfig,
  }) {
    this.mediaType = convertType(mediaType);
  }

  /// 基本功能+水印+上传（压缩后上传）
  ///
  /// 拍照或者选择图片后加水印并上传到七牛
  OpenCustomMediaBean.full({
    @required CustomMediaTyp mediaType,
    this.maxSelectable = 1,
    this.useNativeLoadingDialog = true,
    this.addressWatermark,
    this.waterContent,
    this.uploadConfig,
  }) {
    this.mediaType = convertType(mediaType);
  }

  String convertType(CustomMediaTyp mediaType) {
    String result = "";
    switch (mediaType) {
      case CustomMediaTyp.Camera:
        result = "Camera";
        break;
      case CustomMediaTyp.Gallery:
        result = "Gallery";
        break;
      case CustomMediaTyp.All:
        result = "All";
        break;
    }
    return result;
  }

  OpenCustomMediaBean.fromJson(Map<String, dynamic> json) {
    this.mediaType = json['mediaType'];
    this.addressWatermark = json['addressWatermark'];
    this.useNativeLoadingDialog = json['useNativeLoadingDialog'];
    this.maxSelectable = json['maxSelectable'];
    this.uploadConfig = json['uploadConfig'] != null
        ? UploadConfigBean.fromJson(json['uploadConfig'])
        : null;

    List<dynamic> waterContentList = json['waterContent'];
    this.waterContent = new List();
    this.waterContent.addAll(waterContentList.map((o) => o.toString()));
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['mediaType'] = this.mediaType;
    data['addressWatermark'] = this.addressWatermark;
    data['useNativeLoadingDialog'] = this.useNativeLoadingDialog;
    data['maxSelectable'] = this.maxSelectable;
    if (this.uploadConfig != null) {
      data['uploadConfig'] = this.uploadConfig.toJson();
    }
    data['waterContent'] = this.waterContent;
    return data;
  }
}

class UploadConfigBean {
  String uploadType;
  String picOrigin;

//  UploadConfigBean({this.uploadType, this.picOrigin});
  ///上传到私有-巡房
  UploadConfigBean.privateSaleCheck() {
    this.uploadType = "private";
    this.picOrigin = "saleCheck";
  }

  ///上传到私有-门户
  UploadConfigBean.privatePortal() {
    this.uploadType = "private";
    this.picOrigin = "portal";
  }

  ///上传到私有-收房
  UploadConfigBean.privateSaleIn() {
    this.uploadType = "private";
    this.picOrigin = "saleIn";
  }

  ///上传到私有-出房
  UploadConfigBean.privateSaleOut() {
    this.uploadType = "private";
    this.picOrigin = "saleOut";
  }

  ///上传到公有-门户
  UploadConfigBean.publicPortal() {
    this.uploadType = "public";
    this.picOrigin = "portal";
  }

  ///上传到公有-收房
  UploadConfigBean.publicSaleIn() {
    this.uploadType = "public";
    this.picOrigin = "saleIn";
  }

  ///上传到公有-出房
  UploadConfigBean.publicSaleOut() {
    this.uploadType = "public";
    this.picOrigin = "saleOut";
  }

  ///上传到公有-巡房
  UploadConfigBean.publicSaleCheck() {
    this.uploadType = "public";
    this.picOrigin = "saleCheck";
  }

  UploadConfigBean.fromJson(Map<String, dynamic> json) {
    this.uploadType = json['uploadType'];
    this.picOrigin = json['picOrigin'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['uploadType'] = this.uploadType;
    data['picOrigin'] = this.picOrigin;
    return data;
  }
}

class CustomMediaResultBean {
  ///处理返回路径的回调
  List<String> listResult;

  ///返回图片路径和七牛key的映射
  Map<String, String> mapResult;

  CustomMediaResultBean({this.listResult, this.mapResult});

  CustomMediaResultBean.fromJson(Map<String, dynamic> json) {
    this.listResult = (json['listResult'] as List) != null
        ? (json['failList'] as List).map((i) => i.toString()).toList()
        : null;
    this.mapResult = (json['mapResult'] as Map) != null
        ? (json['mapResult'] as Map).map((dynamic key, dynamic value) {
            return MapEntry<String, String>(key?.toString(), value?.toString());
          })
        : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['listResult'] = this.listResult;
    data['mapResult'] = this.mapResult;
    return data;
  }
}
